package com.twu.biblioteca.Menus;

import com.twu.biblioteca.MenuItems.MenuItem;
import com.twu.biblioteca.MenuItems.ReserveBookItem;
import com.twu.biblioteca.MenuItems.ReturnPreviousMenuItem;
import com.twu.biblioteca.UserAccount;
import com.twu.biblioteca.UserChoice;

import java.util.ArrayList;
import java.util.Iterator;


public class BooksMenu extends Menu {

    private ArrayList<MenuItem> menuItems = new ArrayList<MenuItem>();

    public BooksMenu() {
        description = "Books Menu";
        addItem(new ReserveBookItem("Reserve books"));
        addItem(new ReturnPreviousMenuItem("Return to Main Menu"));
    }



    @Override
    public void addItem(MenuItem menuItem) {

        menuItems.add(menuItem);
    }


    public boolean controller(UserAccount sessionUser) {

        MenuPrinter menuPrinter = new MenuPrinter(this);
        menuPrinter.printMenu();

        UserChoice userChoice = new UserChoice();
        userChoice.setOptionsCount(menuItems.size());
        int option = userChoice.getChoice();

        return menuItems.get(option-1).controller(sessionUser);
     }

    @Override
    public Iterator createIterator() {
        return menuItems.iterator();
    }
}